/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CajeroPagos.java
 *
 * Created on 7/11/2009, 09:58:44 PM
 */

package scapi.gui;

import java.awt.Component;
import java.awt.event.KeyEvent;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import scapi.entidades.BoletaEmpenio;
import scapi.entidades.Pignorante;
import scapi.entidades.Producto;
import scapi.servidor.servidores.ServidorAEmpenio;
import scapi.utilerias.EValidacion;
import scapi.utilerias.ExcepcionValidacion;
import scapi.utilerias.ServidorFactory;

/**
 *
 * @author emmanuel
 */
public class CajeroPagos extends javax.swing.JPanel {
    private ServidorAEmpenio servEmpenio;
    private BoletaEmpenio bol;
    private Pignorante pig;
    private Producto pro;


    /** Creates new form CajeroPagos */

    public CajeroPagos() {

        initComponents();
        try {
            servEmpenio = (ServidorAEmpenio) ServidorFactory.obtenerServidor(ServidorFactory.ServidorEmpenio);
        } catch (RemoteException ex) {
            Logger.getLogger(CajeroPagos.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NotBoundException ex) {
            Logger.getLogger(CajeroPagos.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MalformedURLException ex) {
            Logger.getLogger(CajeroPagos.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        txtClaveBoleta = new javax.swing.JTextField();
        jButtBuscar = new javax.swing.JButton();
        pnDatos = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtNombreBoleta = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtApBoleta = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtRfcBoleta = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jDtFechaBoleta = new com.toedter.calendar.JDateChooser();
        jLabel7 = new javax.swing.JLabel();
        txtProductoBoleta = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtDescBoleta = new javax.swing.JTextArea();
        jLabel9 = new javax.swing.JLabel();
        txtAvaluoBoleta = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtPrestamoBoleta = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        TipoBoleta = new javax.swing.JComboBox();
        jLabelRestante = new javax.swing.JLabel();
        pnPagos = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jDtFechaPago = new com.toedter.calendar.JDateChooser();
        jLabelEstadoPago = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        txtRecibido = new javax.swing.JTextField();
        jButton5 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jRPagoCompleto = new javax.swing.JRadioButton();
        JRPagoParcial = new javax.swing.JRadioButton();
        jLabel19 = new javax.swing.JLabel();
        txtPago = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtRecargos = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jLabelInteresPago = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabelTotalPago = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jDtFechaPrincipal = new com.toedter.calendar.JDateChooser();
        jTextField10 = new javax.swing.JTextField();

        jLabel1.setText("Clave de Boleta");

        txtClaveBoleta.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtClaveBoletaKeyTyped(evt);
            }
        });

        jButtBuscar.setText("Buscar");
        jButtBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtBuscarActionPerformed(evt);
            }
        });

        pnDatos.setBorder(javax.swing.BorderFactory.createTitledBorder("Información de la Boleta"));

        jLabel3.setText("Nombre:");

        txtNombreBoleta.setFocusable(false);

        jLabel4.setText("Apellido:");

        txtApBoleta.setFocusable(false);
        txtApBoleta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtApBoletaActionPerformed(evt);
            }
        });

        jLabel5.setText("RFC:");

        txtRfcBoleta.setFocusable(false);

        jLabel6.setText("Fecha:");

        jDtFechaBoleta.setBackground(new java.awt.Color(255, 255, 255));
        jDtFechaBoleta.setEnabled(false);
        jDtFechaBoleta.setFocusable(false);

        jLabel7.setText("Producto:");

        txtProductoBoleta.setFocusable(false);
        txtProductoBoleta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtProductoBoletaActionPerformed(evt);
            }
        });

        jLabel8.setText("Descripción:");

        txtDescBoleta.setColumns(20);
        txtDescBoleta.setRows(5);
        txtDescBoleta.setEnabled(false);
        jScrollPane1.setViewportView(txtDescBoleta);

        jLabel9.setText("Avaluo:");

        txtAvaluoBoleta.setFocusable(false);

        jLabel10.setText("Prestamo:");

        txtPrestamoBoleta.setFocusable(false);
        txtPrestamoBoleta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPrestamoBoletaActionPerformed(evt);
            }
        });

        jLabel24.setText("Restante:");

        jLabel25.setText("Tipo:");

        TipoBoleta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Semanal", "Mensual" }));

        jLabelRestante.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jLabelRestante.setText("$2500.00");

        javax.swing.GroupLayout pnDatosLayout = new javax.swing.GroupLayout(pnDatos);
        pnDatos.setLayout(pnDatosLayout);
        pnDatosLayout.setHorizontalGroup(
            pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 559, Short.MAX_VALUE)
                    .addGroup(pnDatosLayout.createSequentialGroup()
                        .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnDatosLayout.createSequentialGroup()
                                .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addGroup(pnDatosLayout.createSequentialGroup()
                                        .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel3)
                                            .addComponent(jLabel4)
                                            .addComponent(jLabel6)
                                            .addComponent(jLabel7))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtProductoBoleta, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                                            .addComponent(txtRfcBoleta, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                                            .addComponent(txtApBoleta, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                                            .addComponent(jDtFechaBoleta, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                                            .addComponent(txtNombreBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pnDatosLayout.createSequentialGroup()
                                        .addGap(16, 16, 16)
                                        .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel9)
                                            .addComponent(jLabel25)))
                                    .addGroup(pnDatosLayout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel24)))
                                .addGap(30, 30, 30))
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelRestante)
                            .addComponent(txtAvaluoBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtPrestamoBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(TipoBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        pnDatosLayout.setVerticalGroup(
            pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnDatosLayout.createSequentialGroup()
                .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNombreBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtAvaluoBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtApBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(txtPrestamoBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtRfcBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TipoBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel25))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnDatosLayout.createSequentialGroup()
                        .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jDtFechaBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(txtProductoBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(17, 17, 17)
                        .addComponent(jLabel8))
                    .addGroup(pnDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel24)
                        .addComponent(jLabelRestante)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(62, Short.MAX_VALUE))
        );

        pnPagos.setBorder(javax.swing.BorderFactory.createTitledBorder("Pago"));

        jLabel13.setText("Fecha límite:");

        jDtFechaPago.setEnabled(false);

        jLabelEstadoPago.setFont(new java.awt.Font("Tahoma", 3, 11));
        jLabelEstadoPago.setForeground(new java.awt.Color(51, 204, 0));
        jLabelEstadoPago.setText("A tiempo");

        jLabel17.setText("Recibido:");

        txtRecibido.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtClaveBoletaKeyTyped(evt);
            }
        });

        jButton5.setText("Borrar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton4.setText("Aceptar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel12.setText("Tipo:");

        buttonGroup1.add(jRPagoCompleto);
        jRPagoCompleto.setText("Completo");
        jRPagoCompleto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRPagoCompletoActionPerformed(evt);
            }
        });

        buttonGroup1.add(JRPagoParcial);
        JRPagoParcial.setSelected(true);
        JRPagoParcial.setText("Parcial");
        JRPagoParcial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRPagoParcialActionPerformed(evt);
            }
        });

        jLabel19.setText("Pago");

        txtPago.setFocusable(false);
        txtPago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPagoActionPerformed(evt);
            }
        });

        jLabel11.setText("Recargos");

        txtRecargos.setFocusable(false);
        txtRecargos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtRecargosActionPerformed(evt);
            }
        });

        jLabel20.setText("Intereses");

        jLabelInteresPago.setText("20%");

        jLabel22.setText("Total:");

        jLabelTotalPago.setFont(new java.awt.Font("DejaVu Sans", 0, 24));
        jLabelTotalPago.setForeground(new java.awt.Color(255, 0, 0));
        jLabelTotalPago.setText("00.00");

        jLabel14.setFont(new java.awt.Font("DejaVu Sans", 0, 24));
        jLabel14.setForeground(new java.awt.Color(255, 0, 0));
        jLabel14.setText("$");

        javax.swing.GroupLayout pnPagosLayout = new javax.swing.GroupLayout(pnPagos);
        pnPagos.setLayout(pnPagosLayout);
        pnPagosLayout.setHorizontalGroup(
            pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPagosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnPagosLayout.createSequentialGroup()
                        .addGap(93, 93, 93)
                        .addComponent(jButton4)
                        .addGap(31, 31, 31)
                        .addComponent(jButton5))
                    .addComponent(jLabel12)
                    .addGroup(pnPagosLayout.createSequentialGroup()
                        .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnPagosLayout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelEstadoPago, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jDtFechaPago, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnPagosLayout.createSequentialGroup()
                                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel19))
                                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pnPagosLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jRPagoCompleto)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(JRPagoParcial)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 121, Short.MAX_VALUE))
                                    .addGroup(pnPagosLayout.createSequentialGroup()
                                        .addGap(8, 8, 8)
                                        .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtRecargos, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
                                            .addComponent(txtPago, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)))))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnPagosLayout.createSequentialGroup()
                                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel17)
                                    .addComponent(jLabel20)
                                    .addComponent(jLabel22))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pnPagosLayout.createSequentialGroup()
                                        .addComponent(jLabel14)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabelTotalPago, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabelInteresPago, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(txtRecibido, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGap(22, 22, 22))
        );
        pnPagosLayout.setVerticalGroup(
            pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPagosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel13)
                    .addComponent(jDtFechaPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnPagosLayout.createSequentialGroup()
                        .addComponent(jLabelEstadoPago)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                        .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRPagoCompleto)
                            .addComponent(JRPagoParcial))
                        .addGap(18, 18, 18))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnPagosLayout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(30, 30, 30)))
                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(txtPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtRecargos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(jLabelInteresPago))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel22)
                    .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel14)
                        .addComponent(jLabelTotalPago)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel17)
                    .addComponent(txtRecibido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(69, 69, 69)
                .addGroup(pnPagosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton5))
                .addContainerGap())
        );

        jLabel2.setText("Fecha:");

        jDtFechaPrincipal.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtClaveBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(pnDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(37, 37, 37)
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(jDtFechaPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(pnPagos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtClaveBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtBuscar)
                            .addComponent(jLabel2)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jDtFechaPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnDatos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnPagos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtApBoletaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtApBoletaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtApBoletaActionPerformed

    private void txtProductoBoletaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtProductoBoletaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtProductoBoletaActionPerformed

    private void txtPrestamoBoletaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPrestamoBoletaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtPrestamoBoletaActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jButton5ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        try {
        //Date fechaPago = EValidacion.fecha(jDtFechaPago.getDate());
        String tipo;
        if (jRPagoCompleto.isSelected())
            tipo="completo";
        else
            tipo="parcial";

        float montoPago = EValidacion.flotante(txtPago.getText(), "Monto a Pagar");
       // double recargo = (double)EValidacion.numeroCorrecto(txtRecargos.getText(), "Recargos");
        String interes = jLabelInteresPago.getText();
        double total = EValidacion.flotante(jLabelTotalPago.getText(),"Total");
        double recibido = EValidacion.flotante(txtRecibido.getText(),"Recibido");
        //double cambio = (double) EValidacion.numeroCorrecto(txtCambioPago.getText(),"Cambio");

        
        float cambio = (float) (recibido - montoPago);
        JOptionPane.showMessageDialog(this, "Cambio: " + cambio);
        
        
        servEmpenio.altaPago(1, bol.getId(), pig.getId(), montoPago);



        JOptionPane.showMessageDialog(this, "Pago realizado con exito");
        limpiarForm();

        } catch (ExcepcionValidacion ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(),"ERROR", JOptionPane.ERROR_MESSAGE);
        }catch(Exception e){
            e.printStackTrace();
        }


}//GEN-LAST:event_jButton4ActionPerformed

    private void txtPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPagoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtPagoActionPerformed

    private void txtRecargosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtRecargosActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtRecargosActionPerformed

    private void jButtBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtBuscarActionPerformed
        try{
        int numero = EValidacion.numeroCorrecto(this.txtClaveBoleta.getText(), "Clave de Boleta");
        bol = servEmpenio.obtenerBoleta(numero);

        if(bol == null)
            throw new ExcepcionValidacion("No se han encontrado registros");

        pig = bol.getPignorante();
        pro = bol.getProducto();
       // jDtFechaPago.setDate(servEmpenio.obtenerFechaLimite(bol.getId()));
        float pago = servEmpenio.cantPago(numero);
        float pagoRestante = servEmpenio.cantPagoRestante(numero);

        float recargos = 0;

        //long fechaFin = jDtFechaPago.getDate().getTime();
        //long hoy = new Date().getTime();

        //f(fechaFin > hoy)
           // jLabelEstadoPago.setText("Fuera de tiempo");



        if(!jLabelEstadoPago.getText().equals("A tiempo")){
            recargos = (float) (pago * 0.2);
        }

        float total = pago + recargos;


        txtNombreBoleta.setText(pig.getNombre());
        txtApBoleta.setText(pig.getApPaterno());
        txtAvaluoBoleta.setText(""+bol.getAvaluo());
        txtDescBoleta.setText(pro.getDescripcion());
        txtPrestamoBoleta.setText(""+bol.getPrestamo());
        txtProductoBoleta.setText(pro.getNombre());
        jDtFechaBoleta.setDate(bol.getFecha());
        txtRfcBoleta.setText(pig.getRfc());
        TipoBoleta.setSelectedItem(bol.getLapso());


        jLabelRestante.setText(""+pagoRestante);
        
        txtPago.setText(""+pago);
        txtRecargos.setText(""+recargos);

        jLabelInteresPago.setText(""+bol.getIntereses());

        jLabelTotalPago.setText(""+total);

      
        




        }
        catch(ExcepcionValidacion e){
            JOptionPane.showMessageDialog(this,e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
        }catch(Exception e){
            e.printStackTrace();

        }
    }//GEN-LAST:event_jButtBuscarActionPerformed

    private void txtClaveBoletaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtClaveBoletaKeyTyped
/*     char caracter = evt.getKeyChar();
     if( ((caracter < '0') || (caracter > '9')) &&(caracter != KeyEvent.VK_BACK_SPACE) ){
             evt.consume();}
*/
    }//GEN-LAST:event_txtClaveBoletaKeyTyped

    private void jRPagoCompletoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRPagoCompletoActionPerformed
        try{
                int idBoleta = Integer.parseInt(txtClaveBoleta.getText());

                jLabelTotalPago.setText(""+servEmpenio.cantPagoRestante(idBoleta));
                txtPago.setText(""+servEmpenio.cantPagoRestante(idBoleta));
        }catch(Exception e){

        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jRPagoCompletoActionPerformed

    private void JRPagoParcialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRPagoParcialActionPerformed
       try{
                int idBoleta = Integer.parseInt(txtClaveBoleta.getText());

                jLabelTotalPago.setText(""+servEmpenio.cantPago(idBoleta));
                txtPago.setText(""+servEmpenio.cantPago(idBoleta));
        }catch(Exception e){

        }
    }//GEN-LAST:event_JRPagoParcialActionPerformed


    private void limpiarPanel(JPanel panel){
        Component[] comp = panel.getComponents();
        for (int i = 0; i < comp.length; i++) {
            Component component = comp[i];
            if(component instanceof JTextField){
                JTextField componente = (JTextField) component;
                componente.setText("");
            }else if(component instanceof JComboBox){
                JComboBox comp2 = (JComboBox) component;
                comp2.setSelectedIndex(0);

            }else if(component instanceof JCheckBox){
                JCheckBox box = (JCheckBox) component;
                box.setSelected(false);
            }

        }

    }

    private void limpiarForm(){
        limpiarPanel(pnDatos);
        limpiarPanel(pnPagos);
        txtDescBoleta.setText("");
        jLabelRestante.setText("");
        jLabelTotalPago.setText("");
    }

  

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton JRPagoParcial;
    private javax.swing.JComboBox TipoBoleta;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButtBuscar;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private com.toedter.calendar.JDateChooser jDtFechaBoleta;
    private com.toedter.calendar.JDateChooser jDtFechaPago;
    private com.toedter.calendar.JDateChooser jDtFechaPrincipal;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelEstadoPago;
    private javax.swing.JLabel jLabelInteresPago;
    private javax.swing.JLabel jLabelRestante;
    private javax.swing.JLabel jLabelTotalPago;
    private javax.swing.JRadioButton jRPagoCompleto;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JPanel pnDatos;
    private javax.swing.JPanel pnPagos;
    private javax.swing.JTextField txtApBoleta;
    private javax.swing.JTextField txtAvaluoBoleta;
    private javax.swing.JTextField txtClaveBoleta;
    private javax.swing.JTextArea txtDescBoleta;
    private javax.swing.JTextField txtNombreBoleta;
    private javax.swing.JTextField txtPago;
    private javax.swing.JTextField txtPrestamoBoleta;
    private javax.swing.JTextField txtProductoBoleta;
    private javax.swing.JTextField txtRecargos;
    private javax.swing.JTextField txtRecibido;
    private javax.swing.JTextField txtRfcBoleta;
    // End of variables declaration//GEN-END:variables

}
